package com.xiaoyu.izf.model;

import cn.hutool.core.date.DateUtil;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Objects;

@Entity
@Table(name = "commission_log", schema = "izf", catalog = "")
public class CommissionLog {
    private int id;
    private Integer uid;
    private Integer userVipType;
    private Integer gradeType;
    private Integer totalAmount;
    private String orderId;
    private Integer commissioin;
    private Integer logType;
    private Timestamp logTime;
    private Integer payStatus;
    private Integer sourceUid;
    private Integer isOnline;

    private String logTimeStr;
    private UserInfo sourceUser;
    private UserInfo currentUser;


    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Basic
    @Column(name = "uid")
    public Integer getUid() {
        return uid;
    }

    public void setUid(Integer uid) {
        this.uid = uid;
    }

    @Basic
    @Column(name = "user_vip_type")
    public Integer getUserVipType() {
        return userVipType;
    }

    public void setUserVipType(Integer userVipType) {
        this.userVipType = userVipType;
    }

    @Basic
    @Column(name = "grade_type")
    public Integer getGradeType() {
        return gradeType;
    }

    public void setGradeType(Integer gradeType) {
        this.gradeType = gradeType;
    }

    @Basic
    @Column(name = "total_amount")
    public Integer getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(Integer totalAmount) {
        this.totalAmount = totalAmount;
    }

    @Basic
    @Column(name = "order_id")
    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    @Basic
    @Column(name = "commissioin")
    public Integer getCommissioin() {
        return commissioin;
    }

    public void setCommissioin(Integer commissioin) {
        this.commissioin = commissioin;
    }

    @Basic
    @Column(name = "log_type")
    public Integer getLogType() {
        return logType;
    }

    public void setLogType(Integer logType) {
        this.logType = logType;
    }

    @Basic
    @Column(name = "log_time")
    public Timestamp getLogTime() {
        return logTime;
    }

    public void setLogTime(Timestamp logTime) {
        this.logTime = logTime;
    }

    @Basic
    @Column(name = "pay_status")
    public Integer getPayStatus() {
        return payStatus;
    }

    public void setPayStatus(Integer payStatus) {
        this.payStatus = payStatus;
    }

    @Basic
    @Column(name = "source_uid")
    public Integer getSourceUid() {
        return sourceUid;
    }

    public void setSourceUid(Integer sourceUid) {
        this.sourceUid = sourceUid;
    }

    @Basic
    @Column(name = "is_online")
    public Integer getIsOnline() {
        return isOnline;
    }

    public void setIsOnline(Integer isOnline) {
        this.isOnline = isOnline;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CommissionLog that = (CommissionLog) o;
        return id == that.id &&
                Objects.equals(uid, that.uid) &&
                Objects.equals(userVipType, that.userVipType) &&
                Objects.equals(gradeType, that.gradeType) &&
                Objects.equals(totalAmount, that.totalAmount) &&
                Objects.equals(orderId, that.orderId) &&
                Objects.equals(commissioin, that.commissioin) &&
                Objects.equals(logType, that.logType) &&
                Objects.equals(logTime, that.logTime) &&
                Objects.equals(payStatus, that.payStatus) &&
                Objects.equals(sourceUid, that.sourceUid);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, uid, userVipType, gradeType, totalAmount, orderId, commissioin, logType, logTime, payStatus, sourceUid);
    }

    @Transient
    public String getLogTimeStr() {
        return DateUtil.date(logTime).toString();
    }

    @ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY, optional = true)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "source_uid", referencedColumnName = "id", insertable = false, updatable = false,foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
    public UserInfo getSourceUser() {
        return sourceUser;
    }
    public void setSourceUser(UserInfo sourceUser) {
        this.sourceUser = sourceUser;
    }

    @ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY, optional = true)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "uid", referencedColumnName = "id", insertable = false, updatable = false,foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
    public UserInfo getCurrentUser() {
        return currentUser;
    }
    public void setCurrentUser(UserInfo currentUser) {
        this.currentUser = currentUser;
    }
}
